﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.NetworkService.Behaviors.Interfaces;

namespace Domain.NetworkService
{
    [Serializable]
    public class NetworkServiceTestID
    {
        public IDescription description { get; private set; }
        public string deviceName { get; private set; }

        public NetworkServiceTestID(string deviceName, IDescription description)
        {
            this.deviceName = deviceName;
            this.description = description;
        }
        public override string ToString()
        {
            if (description.GetType() == typeof(EchoDescription))
            {
                EchoDescription d = description as EchoDescription;
                return String.Format("{0} {1} {2}", d.networkTestDescription, 
                                                        d.HostNameOrIP, 
                                                        d.ToString());
            }
            return String.Format("{0} {1} {2} {3}", ((Description)description).networkTestDescription,
                                                    ((Description)description).HostNameOrIP, 
                                                    ((Description)description).Timeout, 
                                                    ((Description)description).Special.Equals(Stub.Absent)
                                                                    ?Stub.Resolve
                                                                    :((Description)description).Special);
        }
        public override bool Equals(Object obj)
        {
            if (obj != null)
            {
                if (GetType() == obj.GetType())
                {
                    NetworkServiceTestID tmp = (NetworkServiceTestID)obj;
                    if (tmp.description.Equals(this.description) &&
                        tmp.deviceName.Equals(this.deviceName))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        public override int GetHashCode()
        {
            return deviceName.GetHashCode() ^ 
                   description.networkTestDescription.GetHashCode() ^
                   description.Special.GetHashCode();
        }
        public static bool operator ==(NetworkServiceTestID a, NetworkServiceTestID b)
        {
            if (System.Object.ReferenceEquals(a, b))
            {
                return true;
            }
            if (((object)a == null) || ((object)b == null))
            {
                return false;
            }
            return a.description == b.description &&
                   a.deviceName == b.deviceName;
                   
        }
        public static bool operator !=(NetworkServiceTestID a, NetworkServiceTestID b)
        {
            return !(a == b);
        }
    }
}
